<?php

namespace app\admin\controller;

use app\admin\builder\Form;
use app\admin\builder\Table;

class Other extends Admin
{
    public function initialize()
    {

        parent::initialize();
    }


    public function _leftSlide()
    {

        $slide = [
            ['title' => '表单1', 'child' => [
                ['menu' => 'admin/other/index', 'query' => ['sss' => 222], 'title' => '表单1', 'slide_name' => 'form'],
            ]],
            ['title' => '权限管理', 'child' => [
                ['menu' => 'admin/other/auth', 'title' => '权限管理', 'slide_name' => 'auth'],
            ]],
        ];

        return $slide;
    }

    public function auth()
    {
        $tag_id = 2;
        if (Request()->isPost()) {
            $input = input('post.');
            $rs = db('user_tag')->where(['id' => $tag_id])->setField('auth', implode(',', $input['menu']));
            if ($rs) {
                $this->success('保存成功');
            } else {
                $this->error('保存失败');
            }
        } else {
            $slide = [];
            $bb = glob(dirname(__FILE__) . '/*.php');
            foreach ($bb as $v) {
                $class_name = '\app\admin\controller' . "\\" . str_replace('.php', '', basename($v));
                if (class_exists($class_name)) {
                    $class = new $class_name();
                    if (method_exists($class, '_leftSlide')) {
                        $s = $class->_leftSlide();
                        if (!empty($s)) {
                            $slide[$class_name] = $s;
                        }
                    }
                }
            }

            $modules = db('module')->where('status', 1)->select();
            foreach ($modules as $v) {
                $class_name = "\app\\{$v['name']}\controller\Admin";
                if (class_exists($class_name)) {
                    $class = new $class_name();
                    if (method_exists($class, '_leftSlide')) {
                        $s = $class->_leftSlide();
                        if (!empty($s)) {
                            $slide[$class_name] = $s;
                        }
                    }
                }
            }

            $auth = db('user_tag')->where(['id' => $tag_id])->value('auth');

            $data['data'] = $slide;
            $data['auth'] = explode(',', $auth);
            $this->_setSlide('auth');
            $this->assign($data);
            $this->_dealMenu();  //这行不要删，用于矫正侧边栏
            $this->assign('seo_title', '权限管理');
            return view('auth');
        }
    }

    public function index()
    {
        $form = new Form();
        if (Request()->isPost()) {
            $form->saveConfig();

        } else {

            $option = [
                ['value' => 'hangzhou', 'title' => '杭州'],
                ['value' => 'huzhou', 'title' => '湖州'],
                ['value' => 'jiaxing', 'title' => '嘉兴'],
                ['value' => 'shanghai', 'title' => '上海'],
            ];
            $option1 = [
                // ''=>'',
                'hangzhou' => '杭州',
                'huzhou' => '湖州',
                'jiaxing' => '嘉兴',
                'shanghai' => '上海',

            ];
            $data = [
                'text' => '这是标题的值',
                'password' => '123456',
                'switch' => '1',
                'select' => 'huzhou',
                'checkbox' => 'jiaxing,huzhou',
                'radio' => 'jiaxing',
                'textarea' => '简介~~~~~',
                'editor' => '详情介绍~~',
                'area' => '330000,330400,330421'
            ];
            //$data =[];
            $this->_setSlide('form');
            return $form->setTitle('ssss')
                ->form(url('index'))
                ->typeText('text', '标题', ['add_btn' => [['text' => '获取', 'data-role' => 'sdfdsf', 'class' => 'sdfsdf'], ['text' => '获取aa', 'data-role' => 'sdfdsf', 'class' => 'layui-btn-warm']]])
                ->typeUploadImage('image1', '上传图片')
                ->typePassword('password', '密码')
                ->typeSwitch('switch', '开关', ['text' => '开|关'])
                ->typeArea('area', '地区')
                // ->typeSwitch('switch1', '开关',['text'=>'开|关'))
                ->typeSelect('select', 'hhh', ['option' => $option1])
                ->typeCheckbox('checkbox', 'abc', ['option' => $option])
                ->typeRadio('radio', 'def', $option)
                ->typeTextarea('textarea', 'fff', [])
                ->typeTime('time', 'time', [])
                ->typeEditor('editor', 'fff', '')
                // ->setData($data)
                ->show();
        }

    }


}
